package com.lx.demonew1.service;

import com.lx.demonew1.dao.AccountDao;
import com.lx.demonew1.entity.Account;
import jakarta.annotation.Resource;
import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {
    @Transactional
    @Override

    public void transferAccount(int fromUserId, int toUserId, float account) {
        Account fromUser = accountDao.findById(fromUserId).get();
        fromUser.setBalance(fromUser.getBalance() - account);
        accountDao.save(fromUser);

        Account toUser = accountDao.findById(toUserId).get();
        toUser.setBalance(toUser.getBalance() + account);
        int zero=1/0;


    }

    @Resource
    private AccountDao accountDao;
}
